/**
 * Created by Administrator on 2017/1/23.
 */
var supplier_token;
$.ajax({
    type:'GET',
    url:'http://192.168.1.72:8098/api/cft/admin/get/token',
    contentType:'application/json; charset=gbk',
    data:'',
    dataType:'json',
    success:function (res) {
        supplier_token = res.data;
        console.log(supplier_token);
    },
    error:function (res) {
        layer.msg('登陆失败');

    }
});
$('#save').click(function () {
    var select_option = $('#select option:selected').val();
    var givefacility_pwd = $('#givefacility_pwd').val();
    var givefacility_usernumber = $('#givefacility_usernumber').val();
    var givefacility_number = $('#givefacility_number').val();
    if(select_option == '' || select_option == null || select_option == undefined){
        layer.msg('请选择店铺')
    }else
    if(givefacility_pwd == '' || givefacility_pwd == null || givefacility_pwd == undefined){
        layer.msg('设备秘钥不能为空');
    }else
    if(givefacility_usernumber == '' || givefacility_usernumber == null || givefacility_usernumber == undefined){
        layer.msg('设备用户号不能为空');
    }else
    if(givefacility_number == '' || givefacility_number == null || givefacility_number == undefined){
        layer.msg('设备序列号不能为空');
    }else{
        console.log('用户名'+ givefacility_usernumber + '密码' + givefacility_pwd + '序列号' + givefacility_number);
        $.ajax({
            type:'post',
            url:'http://192.168.1.72:8098/api/cft/admin/create/device',
            contentType:'application/json',
            data:JSON.stringify({'token':supplier_token,'name':givefacility_usernumber,'shopId':'2','password':givefacility_pwd,'code':givefacility_number}),
            dataType:'json',
            success:function (res) {
                if(res.code == 0){
                    $('#leftcontent', window.parent.document).attr('src','facility.html');
                }else{
                    layer.msg(res.message);
                }

            },
            error:function (res) {
                
            }
        })
    }
});